-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-78502: Add a trackfd parameter to mmap.mmap() on Windows #138238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-78502: Add a trackfd parameter to mmap.mmap() on Windows #138238
Conversation
If trackfd is False, the file handle corresponding to fileno will not be duplicated.
If trackfd is False, the file handle corresponding to fileno will not be duplicated.
d1ce256
to
558beef
Compare
🤖 New build scheduled with the buildbot fleet by @serhiy-storchaka for commit 558beef 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F138238%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-refleak-buildbots label again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not much of a Windows expert, but, the code looks good to me! Thank you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than that condition, looks fine to me.
Modules/mmapmodule.c
Outdated
|
||
#ifdef MS_WINDOWS | ||
if (self->file_handle != INVALID_HANDLE_VALUE) { | ||
if (self->file_handle != INVALID_HANDLE_VALUE || !self->trackfd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like combining an error condition check with a state check like this, it gives us a way to call GetFileSize(INVALID_HANDLE_VALUE, ...)
.
Maybe this should be && self->trackfd
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They both are state checks. The behavior is consistent with Posix -- if trackfd
is false, we get an OSError. We could raise a different error, but then we need to change the Posix code too. Is it fine to do this in this PR, or better open a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should never deliberately pass INVALID_HANDLE_VALUE
to a Win32 API, but we might in this case because of the or condition.
If trackfd
is false, we should just raise an error directly, rather than relying on the OS to generate an error code for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If trackfd is false, we should just raise an error directly, rather than relying on the OS to generate an error code for us.
I agree with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Modules/mmapmodule.c
Outdated
|
||
#ifdef MS_WINDOWS | ||
if (self->file_handle != INVALID_HANDLE_VALUE) { | ||
if (self->file_handle != INVALID_HANDLE_VALUE || !self->trackfd) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If trackfd is false, we should just raise an error directly, rather than relying on the OS to generate an error code for us.
I agree with that.
Co-authored-by: Victor Stinner <[email protected]>
Before merging this PR, it would be convenient to merge #24781. |
…thonGH-138238) If trackfd is False, the file handle corresponding to fileno will not be duplicated.
If trackfd is False, the file handle corresponding to fileno will not be duplicated.
📚 Documentation preview 📚: https://cpython-previews--138238.org.readthedocs.build/